<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>统一认证中心</title>

    <#import "common/common.macro.ftl" as netCommon>
    <@netCommon.commonStyle />
    <link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/iCheck/square/blue.css">
</head>
<body class="hold-transition login-page">

    <div class="login-box">
        <div class="login-logo">
            <a>PerpartnerSSO</a>
        </div>
        <div class="login-box-body">
            <form id="FormID">
                    <p class="login-box-msg">修改密码</p>
                    <div class="form-group has-feedback">
                        <input type="text" name="userId" class="form-control" placeholder="" value="${loginUser.userid}" maxlength="50" readonly >
                        <span class="glyphicon glyphicon-asterisk form-control-feedback"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="text" name="userName" class="form-control" placeholder="" value="${loginUser.username}" maxlength="50" readonly >
                        <span class="glyphicon glyphicon-user form-control-feedback"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" name="oldPassword" class="form-control" placeholder="请输入原始秘密" value="" maxlength="50" >
                        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" name="newPassword" class="form-control" placeholder="请输入新密码" value="" maxlength="50" >
                        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                    </div>

                    <#if errorMsg?exists>
                        <p style="color: red;">${errorMsg}</p>
                    </#if>
            </form>
            <div class="row">
                <div class="col-xs-12">
                    <input type="hidden" name="redirect_url" value="${redirectUrl!''}" />
                    <button type="button" class="btn btn-primary btn-block btn-flat" onclick="submit()">确认修改</button>
                </div>
            </div>
            <div style="padding-top: 10px;">
                <div class="alert alert-success hide"></div>
                <div class="alert alert-danger hide"></div>
            </div>
        </div>
    </div>
</body>
<@netCommon.commonScript />

<script type="text/javascript">

    function submit() {

        var data = $("#FormID").serialize();
        //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
        var submitData=decodeURIComponent(data,true);
        //submitData是解码后的表单数据，结果同上
        $.ajax({
            url: '/system/user/profile/resetPwd',
            data: submitData,
            type: "POST",
            dataType: 'JSON',
            beforeSend:function(){
                //请求前
            },
            success:function(result){
                //请求成功时
                if(result.code == 200){
                    $(".alert-success").text(result.msg)
                    $(".alert-success").removeClass("hide");
                    $(".alert-success").addClass("show");
                    window.setTimeout(function(){
                        $(".alert-success").removeClass("show");
                        $(".alert-success").addClass("hide");
                        //重定向到cms首页
                        window.location.href = $("input[name=redirect_url]").val()
                    },2000);//显示的时间
                }else{
                    $(".alert-danger").text(result.msg)
                    $(".alert-danger").removeClass("hide");
                    $(".alert-danger").addClass("show");
                    window.setTimeout(function(){
                        $(".alert-danger").removeClass("show");
                        $(".alert-danger").addClass("hide");
                    },2000);//显示的时间
                }
            },
            complete:function(){
                //请求结束时
            },
            error:function(){
                //请求失败时
            }
        })
    }
</script>

</html>